package com.rhzy.springbootswagger.controller;

import com.rhzy.springbootswagger.mode.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

@RestController
@Api(value="用户controller",tags={"用户操作接口"})
public class UserController {

    @ApiOperation(value = "标题描述", notes = "详细描述")
    @GetMapping("/getUserName")
    public String getUserName(){
        return "username";
    }

    @ApiOperation(value="标题-添加用户信息", notes = "详细-添加用户信息")
    @ApiParam(name="user", value="用户对像", required = true)
    @PostMapping("/addUser")
    public String addUser(@RequestBody User user){
        System.out.println(user.getUsername());
        return "success";
    }
    @ApiOperation(value="标题-文件上传", notes = "详细-文件上传")
    @PostMapping(value = "/upload",consumes = "multipart/*", headers = "content-type=multipart/form-data")
    public String upload(MultipartFile multipartFile){
        try {
            InputStream inputStream = multipartFile.getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String fileName = Long.toString(multipartFile.getSize());
        return fileName;
    }
}
